package com.test.controller;


import com.test.domain.Dish;
import com.test.domain.Result;
import com.test.domain.Utils;
import com.test.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@CrossOrigin
@RestController
@RequestMapping("/dish")
public class DishController {

    private final DishService dishService;

    @Autowired
    public DishController(DishService dishService) {
        this.dishService = dishService;
    }


    //插入菜品
    @PostMapping("/insertDish")
    public Result insertDish(@RequestBody Dish dish){
        System.out.println(dish);
        dishService.insertDish(dish);
        return Utils.success("ok");
    }

    @GetMapping("dishList")
    public Result getDishList(@RequestParam("phoneNumber") String phoneNumber){
        System.out.println(phoneNumber);
        return Utils.success(dishService.getDishList(phoneNumber));
    }

    @GetMapping("/updateDishName")
    public Result updateDishName(@RequestParam("dishNumber") String dishNumber,
                                 @RequestParam("dishName") String dishName){
        System.out.println(dishNumber);
        System.out.println(dishName);
        dishService.updateDishName(dishNumber,dishName);
        return Utils.success("ok");
    }

    @GetMapping("/updateDishDescription")
    public Result updateDisDescription(@RequestParam("dishNumber") String dishNumber,
                                 @RequestParam("dishDescription") String dishDescription){
        System.out.println(dishNumber);
        System.out.println(dishDescription);
        dishService.updateDishDescription(dishNumber,dishDescription);
        return Utils.success("ok");
    }

    @GetMapping("/updateDishPrice")
    public Result updateDishPrice(@RequestParam("dishNumber") String dishNumber,
                                  @RequestParam("dishPrice")BigDecimal dishPrice){
        System.out.println(dishNumber);
        System.out.println(dishPrice);
        dishService.updateDishPrice(dishNumber,dishPrice);
        return Utils.success("ok");
    }

    @GetMapping("/updateIsSale")
    public Result updateIsSale(@RequestParam("dishNumber") String dishNumber,
                                  @RequestParam("isSale")int isSale){
        System.out.println(dishNumber);
        System.out.println(isSale);
        dishService.updateIsSale(dishNumber,isSale);
        return Utils.success("ok");
    }

    @GetMapping("/deleteDish")
    public Result deleteDish(@RequestParam("dishNumber") String dishNumber){
        dishService.deleteDish(dishNumber);
        return Utils.success("ok");
    }


}
